import React from "react";
import Workflow from "@/services/workflow";
import {Button, Divider, Select,Layout} from "antd/lib";
import {convertStringToComponent} from "@/components/contract/utils";
import notification from "@/services/notification";
import Templates from "@/services/templates";
import 'braft-editor/dist/index.css'
import BraftEditor from 'braft-editor'
//const timer_str = convertComponentToString(df)
const {Sider,Content } = Layout;
// 将转化的组件字符串再转为组件
// const TimerComponent = convertStringToComponent(this.props.templatecontent)
export default class LookTemplatetext extends React.Component {
    state = {
      templateid: 1,
      templatecontent: "",
      templatename:"",
      loading: true,
      tdata:[],
  };
  componentWillMount() {
      let templatecontent=this.props.templatecontent;
      if(this.props.templateid===0  && templatecontent !==''){
        templatecontent=templatecontent.replace('.docx','.pdf');
        templatecontent=templatecontent.replace('.doc','.pdf');//"+templatecontent+"'http://ht.cdlyy.com:10001/
        if(document.querySelector('body').offsetWidth>600){
          templatecontent="<div><iframe src='"+templatecontent+"' width='100%' height='800px' frameborder='1'></iframe></div>"
        }else{
          templatecontent="<div><iframe src='static/file/pdfjs/web/viewer.html?file=http://ht.cdlyy.com:10001/"+templatecontent+"' width='100%' height='800px' frameborder='1'></iframe></div>"
        }
      }
      this.setState({
        templateid: this.props.templateid,
        templatecontent: templatecontent,
        templatename:this.props.templatename,
      });
      let param={
        page: 1,
        pagesize: 20,
        code: "",
        name: "",
        type: "contract",
      }
       Templates.getlist(param).then(data => {
          this.setState({
              loading: false,
              tdata:data.data,
          });
      });

  }
    componentDidUpdate() {
        document.getElementById("goods_detail_contentsel").innerHTML = this.state.templatecontent;
    }
    componentWillReceiveProps(nextProps) {//componentWillReceiveProps方法中第一个参数代表即将传入的新的Props
      let templatecontent=nextProps.templatecontent;
      if(nextProps.templateid===0  && templatecontent !==''){
        templatecontent=templatecontent.replace('.docx','.pdf');
        templatecontent=templatecontent.replace('.doc','.pdf');
        if(document.querySelector('body').offsetWidth>600){
          templatecontent="<div><iframe src='"+templatecontent+"' width='100%' height='800px' frameborder='1'></iframe></div>"
        }else{
          templatecontent="<div><iframe src='static/file/pdfjs/web/viewer.html?file=http://ht.cdlyy.com:10001/"+templatecontent+"' width='100%' height='800px' frameborder='1'></iframe></div>"
        }
      }
      this.setState({
        templateid: nextProps.templateid,
        templatecontent: templatecontent,
        templatename:nextProps.templatename,
      });
 }

render() {
      return (
          <div>
            <div style={{ marginBottom: 16 }}>
              <span style={{ marginLeft: 8 }}>
                模版：
              </span>
              {this.props.templatename}
            </div>
          <div id="goods_detail_contentsel"/>
        </div>
      );
    }
}